<template>
  <div class="nav" :style="isOpacity" v-show="isOpacity.opacity">
    <router-link class="return" tag="div" to="/">
      <i class="iconfont icon-fanhui"></i>
    </router-link>
    <h4>{{this.sightName}}</h4>
  </div>
</template>
<script>
export default {
  name: "DetailNav",
  props: ["sightName"],
  data() {
    return {
      isOpacity: {
        opacity: 0
      }
    };
  },
  mounted() {
    window.addEventListener("scroll", this.handleScroll);
  },
  destroyed() {
    window.addEventListener("scroll", this.handleScroll);
  },
  methods: {
    handleScroll() {
      var top = document.documentElement.scrollTop || document.body.scrollTop;
      var opacity = top / 500;
      if (opacity >= 1) {
        opacity = 1;
      }
      this.isOpacity.opacity = opacity;
    }
  }
};
</script>
<style lang="scss" scoped>
@import "../../../assets/style/scss/global";
.nav {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 40px;
  background: color(bg);
  display: flex;
  line-height: 40px;
  align-items: center;
  justify-content: center;
  color: #fff;
  .return {
    position: absolute;
    left: 20px;
    i {
      font-size: 20px;
    }
  }
}
</style>
